package com.tdw.eurekaclient.service;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;


@Service
public class HystrixService {
	private static final Logger logger = LoggerFactory.getLogger(HystrixService.class);
	
	@Autowired
	private RestTemplate restTemplate;
	
	@HystrixCommand(fallbackMethod = "hystrixTestFallback")
	public String hystrixTest(String parmUrl,Map<String,String[]> parmMap){
		return restTemplate.getForEntity("http://hello-service/hystrix/test?"+parmUrl, String.class,parmMap).getBody();
	}
	
	
	
	public String hystrixTestFallback(String parmUrl,Map<String,String[]> parmMap){
		logger.error("request err , hystrix fall back , logger to file ,log info :parmUrl={},parmMap={}",parmUrl,parmMap);
		return "hystrixTestFallback";
	}
	
	
}
